<?php
namespace app\admin\controller;
use think\Db;

class User
{
	public function __construct(){
		Admin_auth();
	}
	
    public function index()
    {
		$pages = pages('user',['type'=>2],input('get.page'));
		$data = Db::table("user")->limit($pages['limit'])->order('id desc')->select();
        return view('',['data'  => $data,'pages' => $pages['pages']]);
    }
	
	public function edit()
    {
        $id = (int)request()->get('id');
		if(request()->isPost()){
			$data = request()->post();
			if($id){
				Db::table("user")->where('id',$id)->update($data);
			}else{
				$data['regtime'] = time();
				$id = Db::table("user")->insertGetId($data);
                Db::table('user')->where('id',$id)->update(['token'=>md5($id)]);
            }
		}
        $data = Db::table("user")->where(['id' => $id])->find();
        return view('',['data'  => $data]);
    }
	
	public function del()
    {
		$id = (int)request()->get('id');
		$page = input("get.page");
		Db::table("user")->whereIn('pid',session('wmo2o_a_pid'))->delete($id);
		redirect(url('user/index').'?page='.$page);
		exit;
    }
}
